import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsIn, IsInt, IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
import { ICreateRole, ROLE_STATUS_VALUES } from '@nbase/shared';
import { Type } from 'class-transformer';

/**
 * 创建角色 DTO
 */
export class CreateRoleDto implements ICreateRole {
  @ApiProperty({
    description: '角色代码',
    example: 'ADMIN',
    maxLength: 128,
  })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  code!: string;

  @ApiProperty({
    description: '角色名称',
    example: '管理员',
    maxLength: 128,
  })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  name!: string;

  @ApiPropertyOptional({
    description: '状态（1.启用 2.禁用）',
    example: 1,
    enum: ROLE_STATUS_VALUES,
  })
  @Type(() => Number)
  @IsInt()
  @IsIn(ROLE_STATUS_VALUES)
  status!: number;

  @ApiPropertyOptional({
    description: '角色描述',
    example: '系统管理员角色',
    maxLength: 256,
  })
  @IsOptional()
  @IsString()
  @MaxLength(256)
  description?: string;
}

